package com.fira.web.controller.index;

import com.fira.common.core.controller.BaseController;
import com.fira.common.core.domain.AjaxResult;
import com.fira.common.utils.DateUtils;
import com.fira.edu.domain.vo.MonthAmountVO;
import com.fira.edu.service.IEduClassService;
import com.fira.edu.service.IEduStudentService;
import com.fira.web.controller.index.domain.MainVO;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 首页Controller(已废弃)
 * @author tony
 * @date 2021-10-23
 */
@Controller
@RequestMapping("/main/index")
public class MainController extends BaseController {
    @Autowired
    private IEduStudentService eduStudentService;
    @Autowired
    private IEduClassService eduClassService;

    public String toIndex(ModelMap modelMap){
        return "main";
    }

    @RequestMapping("getData")
    @ResponseBody
    public AjaxResult getIndexData(){
        //查询图表统计数据
        List<MonthAmountVO> monthData = eduStudentService.selectMonthAmountOfYear();
        Integer todayStuCount = eduStudentService.selectStuCountOfToday();
        Integer todayClassCount = eduClassService.selectCountClassOfToday();
        Integer stuCount = eduStudentService.selectStuCount();
        MainVO vo = new MainVO();
        vo.setStuCount(stuCount);
        vo.setTodayStuCount(todayStuCount);
        vo.setTodayClassCount(todayClassCount);
        if(CollectionUtils.isNotEmpty(monthData)){
            List<String> monthList = new ArrayList<>();
            List<BigDecimal> amountList = new ArrayList<>();
            monthData.forEach(item -> {
                monthList.add(item.getTime());
                amountList.add(item.getValue());
            });
            vo.setMonthList(monthList);
            vo.setAmountList(amountList);
        }
//        vo.setMonthAmount(monthData);
        return AjaxResult.success(vo);
    }
}
